<?php

class Plyte_Request extends Core_Request {
	
	public function __construct($uri = null) {
		parent::__construct($uri, Route::all(), Plyte::$base_url);
	}

	public static function factory($uri = null) {
		return new Request($uri);
	}

	// Same as Core_Request, but using the new hotness
	public function execute() {
		$previous         = Request::$_current;
		Request::$_current = $this;
		
		if (($callback = $this->route->callback()) === false) {
			Request::$_current = $previous;

			return $this->response;
		}

		if (is_array($callback) && class_exists('ReflectionClass')) {
				$reflector = new ReflectionClass($callback[0]);

				$class = $reflector->newInstance();

				$reflector->getMethod($callback[1])->invokeArgs($class, array(&$this));
		} elseif (is_string($callback)) {
			if (strpos($callback, '::') && class_exists('ReflectionClass')) {
				$callback = explode('::', $callback);

				$reflector = new ReflectionClass($callback[0]);

				$class = $reflector->newInstance();

				$reflector->getMethod($callback[1])->invokeArgs($class, array(&$this));
			} else {
				$callback($this);
			}
		}

		Request::$_current = $previous;

		return $this->response;
	}

}